<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>设备信息</title>
  <script type="text/javascript">
    /*
     * 创建XHR
     */
    function createXHR() {
      try {
        // Firefox, Opera 8.0+, Safari
        xhr = new XMLHttpRequest();
      }
      catch (e) {
        // Internet Explorer
        try {
          xhr = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
          try {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch (e) {
            alert("您的浏览器不支持AJAX！");
            return false;
          }
        }
      }
      return xhr;
    }

    /*
     * 回调函数
     */
    function callbackFunction() {
      if (xhr.readyState == 4) {
        if (xhr.status == 200) {
          var returnValue = xhr.responseText;

          if (returnValue != null && returnValue.length > 0) {
            console.log(returnValue);
            dataProcess(returnValue);
          }
          else {
            console.log("结果为空！");
          }
        }
        else {
          console.log("页面出现异常！");
        }
      }
    }

    /*
     * 数据处理
     */
    function dataProcess(returnValue) {
      //以/\n切割字符串
      var str0 = returnValue.split('/');
      if (!Array.prototype.forEach) //判定浏览器是否支持foreach函数,解决IE无法支持的问题
      {

        Array.prototype.forEach = function forEach(callback, thisArg) {
          var T, k;

          if (this == null) {
            throw new TypeError("this is null or not defined");
          }
          var O = Object(this);
          var len = O.length >>> 0;
          if (typeof callback !== "function") {
            throw new TypeError(callback + " is not a function");
          }
          if (arguments.length > 1) {
            T = thisArg;
          }
          k = 0;
          while (k < len) {
            var kValue;
            if (k in O) {
              kValue = O[k];
              callback.call(T, kValue, k, O);
            }
            k++;
          }
        };
      }
      str0.forEach(function (eachData) {
        //以=切割字符串	
        var str1 = eachData.split("=");
        //console.log(str1[0]);
        switch (str1[0]) {
          case "FirmwareVersion":
            document.getElementById("FirmwareVersion").innerText = str1[1];
            break;
          case "readend":
            xhr.abort();
            break;
        }
      })
    }

    /*
     * 获取设备信息
     */
    function GetDevinfo() {
      var xhr;
      xhr = createXHR();
      if (xhr) {
        xhr.onreadystatechange = callbackFunction;
        xhr.open("GET", "/cgi-bin/devinfo.cgi?getdevinfo");
        xhr.send(null);
      }
      else {
        //XMLHttpRequest对象创建失败
        alert("浏览器不支持，请更换浏览器！");
      }
    }

    /*
     * 加载函数
     */
    window.onload = function () {
      GetDevinfo();
    }
  </script>
</head>

<body>
  <div style="padding: 20px;padding-top: 30px;">
    <div style="height: 30px">
      <span id="FirmwareVersion" style="width: 150px;display:inline-block;">固件版本: --</span>
    </div>
  </div>
</body>

</html>